s = input()
mx  = 0
if len(s) == 4:
    a = [s[0], [s[1], [s[2], [s[3], [s[0:2], [s[1:3], [s[2:4], [s[0:3], [s[1:4], s]
    for j in range(len(a)):
        n = int(a[j])
        c = 0
        for i in range(1, n//2+1):
            if n%i == 0:
                c+=1
        if c == 2 and n!=1:
            mx = max(mx, n)
print(mx)
